<?PHP
 session_start();
 include("admin/include/db.php");
 include("includes/session.php");
 
 $userId = $_SESSION['user_id'];
 
 
function upLoadPic1($name,$id)
{
	$cl = trim($name['name']);
	$pic="";
	$fileName="";
	if(isset($cl) and $cl != "")
	{
		$temp_fileName = explode(".", $name['name']);
		if(!file_exists("upload_images/"))
		mkdir("upload_images/", 0777);
		$uploadDir = "upload_images/";
		$uploadFile = $uploadDir.$id;
		if( move_uploaded_file($name['tmp_name'], $uploadFile) )
		{
			return $id;
		}else{
			return "error";
		}
	}

}


 if(isset($_REQUEST) && $_REQUEST['submit'] != ''){ 

	$documents 		   		= time().'_'.$_FILES['documents']['name'];
 	$documentFile 	 		= upLoadPic1($_FILES['documents'], $documents); 
	$title					= $_REQUEST['title'];
	
	$sqlDocuments			= "INSERT INTO software_teacher_doc 
										SET
											teacher_id	=	'". intval($_SESSION['user_id']) ."',
											title		=   '". mysql_real_escape_string( $title ) ."',
											date		=    unix_timestamp(),
											documents	=   '". $documentFile . "'
							  ";	
	mysql_query($sqlDocuments);
	header("location:trainer_upload_documents.php?msg=1");
	exit();
 }
 
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?=TITLE_WEBSITE?></title>
<link rel="stylesheet" type="text/css" href="css/style.css">
</head>
<center>
<div style="background:#179cc1; height:3px">&nbsp;</div>
<div style="width:990px;" align="center">
		<div id="header">
		<?php
    		include("includes/header.php");
   		?>
        </div>
    <div style="margin-top:20px;  min-height:500px !important">
    	 <div style=" width:25%; float:left" >
        	 <?php include("includes/trainerLeftMenu.php");?>
        </div>
        <div style="width:75%;float:left">
        	<div style="margin-top:20px;">
    	<form id="form_login" name="form_login" method="post" onsubmit="return login_validation()" >
    	<?php
		$msg = $_REQUEST['msg'];
        if($msg != "")
		{
			if($msg == 1){
				$showMessage = 'Your document is uploaded successfully';
				$clsMessage = 'clsSuccess';	
			}
		
		?>
        <div align="left" class="<?=$clsMessage?>" style="margin-bottom:10px" >
           &nbsp; 	 <?=$showMessage?>
        </div>
        <?php
		}
		?>
        
        </form>
        <form id="form_register" name="form_register" method="post" onsubmit="return register_validation()" enctype="multipart/form-data" >
        <div style="width:85%; margin-left:40px" >
        	<div align="left" >
            	<span class="headingOrange" ><strong>Upload your documents</strong></span>
            </div>
            <div class="text1"  align="left" style=" padding-top:18px;">
         		 <div  >	
                    <div style="float:left; width:30%" class="text" >Document Title:</div>
                    <div style="float:left; width:70%" ><input type="text" id="title" class="textBox" name="title" value="" maxlength="30" /> </div>
                    <div style=" clear:both" ></div>
                </div>
                
                <div  style="margin-top:10px" >	
                  <div style="float:left; width:30%" class="text" >Upload your document:</div>
                  <div style="float:left; width:70%" ><input type="file" id="documents" class="textBox" name="documents" value="" maxlength="30" /> </div>
                </div>
                <div style="margin-top:10px" >&nbsp; </div>
                
                 <div style="margin-top:10px;" align="center">	
                 	<input type="hidden" id="action" name="action" value="Update"  />
                   	<input type="submit" class="button" name="submit" id="submit" value="Upload Documents"  />
                </div>
                 
            </div>
        </div>
        </form>
      <div style="clear:both"></div>
    </div>
        	
        </div>
        <div style="clear:both"></div>
    </div>
    
    <div style="margin-top:23px; margin-bottom:21px" align="center" >
    	<?php
									$sqlAdvertise = mysql_query("SELECT * FROM software_advertise 
																	WHERE 
																		banner_status = 'Y' AND banner = 2
																		ORDER BY RAND()
																		");
									$resAdvertise = mysql_fetch_array($sqlAdvertise);
							
									$imgPath  = 'admin/upload_images/'.$resAdvertise["banner_image"];
									
								?>
								
   </div>
   </div>
            
   <div id="footer">
  		
		<?php include("includes/footer.php")?>
   </div>
</div>
	</div>
</center>
</body>
</html>
